package com.gizwits
import scala.util.control.Breaks._
import com.gizwits.javautil.utils
import com.gizwits.util._
import org.apache.commons.codec.binary.{Hex, Base64}
  object Base64test {

    //返回len,跟msg_len(可变长度的长度[1,4],msg_len[0,255*255*255*255])
    def get_msg_len(data:Array[Byte]):(Int,Int) = {
      var ret = 0;
      var len = 0;
      breakable {for {i <- 0 to 3} {
        ret += (data(4+i) & 0x7F) << (7 * i)
        len = i+1
        if ((data(4+i) & 0x80) == 0) {
          break
        }
      }}
     (len,ret-4)
    }
    def main(args: Array[String]) {
      val  payload="AAAAAyIAAJEEAAAAAAABAAAAJwAAABQAAAB7AAAAPwAAAAAAAABi"
  val s= Base64.decodeBase64(payload)

      println("byte length "+s.length)
      println(s.toList)
      println(s.toList.length)
      println(s.foreach(print _))
     // println(s.slice(5,39))
      //9
      println(s.slice(9,10).toList.head)

      println(s.toList.slice(15,19))  //1

    //  println(java.nio.ByteBuffer.wrap(s.slice(15,19)).getInt)
     // println(bytesToUint32(s.slice(15,19),0))
    //  println(Bits.toBitSet(s.toList.slice(9,10)).head)
     // println(Hex.encodeHexString(s.slice(8,39)))
      // println(Hex.encodeHexString(s.slice(8,9)))
    //  println(Bits.toBitSet(s.slice(9,10)).head)
    //  println(Bits.toBitSet(s.slice(8,9)).head)
     // println(s.slice(9,10))
   //   val b=Bits.toBitSet(s).slice(0,1)
    //  println(Hex.encodeHexString(Bits.fromBitSet(b)))
   // println(utils.bytes2Hex(s))
//      println(Hex.encodeHexString(s))
      val h=CommonUtil.base64hexString(payload)
     println(h)
      println(h.length)
     println(get_msg_len(s))


  }

}
